package com.tuyue.police.dao;

import com.tuyue.police.pojo.Rule;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @Author: 王金海
 * @Description:
 * @Date: Created by Administrator on 2018/3/13.
 * @Modified By:
 */
public interface IRuleDao extends JpaRepository<Rule,Long> ,JpaSpecificationExecutor<Rule>{

    @Query("select r from Rule r where r.ruleUserId=?1")
    Page<Rule> findAllByRuleUserId(Long userId, Pageable pageable);

    @Query(value = "SELECT r.* FROM\n" +
            "  rule AS r INNER JOIN rule1 AS r1 ON (r.rule_id=r1.rule1_rule_id) INNER JOIN sector AS s ON (s.sector_id=r1.rule1_sector_id)\n" +
            "WHERE s.sector_id=?1",nativeQuery = true)
    List<Rule> findAllBySectorId(Long sectorId);
}
